package bavaria.hightech.formatter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Iterator;

import bavaria.hightech.banking.Account;


import bavaria.hightech.booking.Booking;
import bavaria.hightech.booking.Sortmethod;

public class FormatPlain implements FormatterInterface {

	@Override
	public void createStetement(Account acc, Sortmethod comp) throws IOException {
		
File file = new File("c:/statement.txt");
		
		BufferedWriter bw = new BufferedWriter(new FileWriter(file));
		
		Collections.sort(acc.getList(), comp.comperator);
		
		Iterator<Booking> iter = acc.getList().iterator();
		
		
		
		bw.write(acc.getAccountNumber()+acc.getAccountOwner()+acc.getAccountBalance());
		bw.newLine();
	
		
		while(iter.hasNext()) {
			bw.write(iter.next().getReference()+" " +iter.next().getDate().getTime());
            bw.newLine();
			
		}
		
		
		bw.close();
	}
}
